import CommentList from './comment-list.html';
import _ from 'underscore';
import Util from '../../../common-component/util/util.js';
import Table from '../../../common-component/table/table.js';
import Address from '../../../common-component/address/address.js';
import API from '../../../api/Api.js';
import Dialog from '../../../common-component/dialog/dialog.js'
import ChoiceDialog from '../../../common-component/choice-dialog/choice-dialog.js';
import Pagination from '../../../common-component/pagination/pagination.js';
import Api from '../../../api/Api.js';
import ServiceCommon from '../../service-common/service-common.js';

import "../comment.scss";

export default function CompanyCity() {
    const FIRST_PAGE = 1, PAGE_SIZE = 10;
    $("#app-container").html( CommentList() );

    //初始化参数对象
    this.params = {
        pageNO: FIRST_PAGE,
        pageSize: PAGE_SIZE
    },
        this.querySearch = null;
    this.data = [];
    var _this = this;

    var tHeader = [
        {CHECKBOX:true,name:'employeeId'},
        {title: '留言者身份', width: '120px', name: 'title', handler: function(str){
            return str;
        }}
        , {title: '姓名', name:  'PV', handler: function(str){
            return str;
        }}
        , {title: '电话', name:  'status', handler: function(str){
            return str;
        }}
        , {title: 'Email',  name:  'index', handler: function(str){
            return str;
        }}
        , {title: '审核',  name:  'status', handler: function(str){
            return str;
        }}
        , {title: '提交时间', width: '120px',  name:  'updateTime', handler: function(str){
            return str;
        }}
        , {title: '操作', width: '100px', hasFunc: true
            , funcList:
            [{name:'查看', op: 'detail', cls: 'comment-detail'}
                ,{name:'删除', op: 'delete', cls: 'comment-delete'}]}
    ];
    var data = [{
        title:'嗨皮',
        PV: '23',
        updateTime: '2017-11-22',
        status: '下架',
        index: '0',
    },{
        title:'嗨皮1',
        PV: '231',
        updateTime: '2017-11-22',
        status: '置顶',
        index: '1',
    },{
        title:'嗨皮2',
        PV: '232',
        updateTime: '2017-11-22',
        status: '推荐',
        index: '2',
    },{
        title:'嗨皮3',
        PV: '233',
        updateTime: '2017-11-22',
        status: '推荐',
        index: '3',
    },{
        title:'嗨皮4',
        PV: '234',
        updateTime: '2017-11-22',
        status: '下架',
        index: '4',
    },];
    Table($(".commentList"),'commentList',{
        tHeader: tHeader,
        data: data
    });

    const handlers = {
        checkedList: null,
        isAjax: false,
        querySearch: null,
        params: {
            pageNO: 1,
            pageSize: 10
        },
        init: function(evt) {
            const _this = this;
            this.queryForm().bindEvent();
            /*   this.querySearch = Pagination('#pagination', {
             pageSize: 10,
             url: API.queryEmployee,
             data: _this.params,
             type: 'get',
             changeParam: function(setParam, pageNO, pageSize) {
             _this.params.pageNO = pageNO;
             _this.params.pageSize = pageSize;
             setParam(_this.params);
             },
             success: function(json) {
             _this.checkedList = Table($(".news-table"), 'news-table', {
             tHeader: tHeader,
             data: json.list,
             opFunction: (obj) => {
             _this.FormButton(obj);
             }
             },() => {
             $(".news-table").colResizable({
             minWidth: 100,
             selfResize: true
             });
             });
             },
             error: function() {

             },
             complete: function() {

             }
             })*/
        },
        /*
         * 表单按钮操作
         * */
        FormButton: function (e) {
            console.log(e)
            switch(e.op)
            {
                case 'detail'://查看
                    window.location.href = '#/comment-detail'
                    break;
                case 'delete':// 删除

                    break;
            }
        },
        /**
         * 绑定事件
         */
        bindEvent: function() {
            const _this = this;
            $("body").on('click', '.js-handle', function(e) {
                const $this = $(this), handle = $this.data('handle');
                _this[handle] && _this[handle]($this, e);
            })
                .on('click', '.main-data', function() {
                    const $this = $(this), idx = $this.index();
                    if(_this.isAjax) {
                        return;
                    }
                    $this.addClass('active').siblings().removeClass('active');
                });
            return this;
        },
        /**
         * 处理数据
         */
        processingData: function(data=[]) {
            data.map((item)=>{
                console.log(item)
            })
        },
        /**
         * 获取数据
         * @param 获取后的回调
         */
        getItems: function(cawllback) {
            this.ajaxHandle();
        },
        /**
         * ajax统一处理
         */
        ajaxHandle: function() {

        },
        /**
         * 统一提示语
         * @param msg 提示消息 string
         */
        tips: function(msg) {
            Util.alertMessage(msg);
        },
        /**
         * 获取选中数据
         */
        getTableCheckedData: function(){
            if(!this.checkedList) {
                return;
            }
            return this.checkedList();
        },
        /*
         * 批量删除
         * */
        delete: function () {

        }
    }

    handlers.init();


    var v = $('#query_form').easyform();
    v.success = function (ef){//验证成功
        handlers.params = $(ef.form).serializeObject(handlers.params);
        handlers.querySearch(handlers.params);
    }
    $('#resetBtn').on('click',function(){
        $('input[name=addressCode],input[name=companyCode]').val('');
        window.setTimeout(function(){
            handlers.params = $('#query_form').serializeObject(handlers.params);
            handlers.querySearch(handlers.params);
        },500);
    });

}
